import Vue from 'vue'
import Vuex from 'vuex'

// import { openApiSysCourseQuery } from '@/api/admin/courseLibrary/sysCourse'

import {
  sysCourseQuery,
  sysCourseQueryById,
  sysCourseAdd,
  sysCourseUpdate,
  openApiSysCourseQuery,
  openApiSysCourseRelatedRecommend,
} from '@/api/admin/course/sysCourse.js'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  async queryOpenApiSysCourseList({ commit }, listQuery) {
    let res = await openApiSysCourseQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },

  async querySysCourse({ commit }, listQuery) {
    let res = await sysCourseQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async querySysCourseById({ commit }, id) {
    let res = await sysCourseQueryById(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addSysCourse({ commit }, data) {
    let res = await sysCourseAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateSysCourse({ commit }, data) {
    let res = await sysCourseUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryOpenApiSysCourse({ commit }, listQuery) {
    let res = await openApiSysCourseQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryOpenApiSysCourseRelatedRecommend({ commit }, listQuery) {
    let res = await openApiSysCourseRelatedRecommend({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
